package middleware

import (
	"gin-skeleton/core"
	"gin-skeleton/core/logger"
	"github.com/gin-gonic/gin"
	uuid "github.com/satori/go.uuid"
)

func LogTraceIdMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		traceId, ok := c.Value(core.RequestID).(string)
		if !ok {
			traceId = uuid.NewV4().String()
		}
		c.Set(core.RequestID, traceId)
		logger.SetTraceId(traceId)
		c.Next()
	}
}
